import 'dart:io';

import 'package:flutter/material.dart';
import 'package:hospitable_rental/pages/room/publish/room_applicance.dart';
import 'package:hospitable_rental/routes/routes.dart';
import 'package:hospitable_rental/utils/comme_picker/common_image_picker.dart';
import 'package:hospitable_rental/widgets/common_floating_action_button.dart';
import 'package:hospitable_rental/widgets/form_item/common_form_item.dart';
import 'package:hospitable_rental/widgets/form_item/common_radio_form_item.dart';
import 'package:hospitable_rental/widgets/form_item/common_select_form_item.dart';
import 'package:hospitable_rental/widgets/form_item/common_title.dart';

class RoomPublishPage extends StatefulWidget {
  const RoomPublishPage({Key? key}) : super(key: key);

  @override
  _RoomPublishPageState createState() => _RoomPublishPageState();
}

class _RoomPublishPageState extends State<RoomPublishPage> {
  int _rentType = 0;
  int _decorationType = 0;
  int? _roomType;
  int? _floorType;
  int? _orientedType;

  late TextEditingController _info;
  late TextEditingController _desc;

  @override
  void initState() {
    _info = TextEditingController();
    _desc = TextEditingController();
    super.initState();
  }

  @override
  void dispose() {
    _info.dispose();
    _desc.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("房屋发布"),
      ),
      body: ListView(
        children: [
          CommonTitle("房屋信息"),
          CommonFormItem(
            "小区",
            contentBuilder: (context) {
              return Container(
                height: 40.0,
                child: GestureDetector(
                  behavior: HitTestBehavior.translucent, // 点击空白区域也生效
                  onTap: () => Navigator.of(context).pushNamed(Routes.notFound),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        "请选择小区",
                        style: TextStyle(
                          fontSize: 14.0,
                          color: Colors.black,
                        ),
                      ),
                      Icon(
                        Icons.keyboard_arrow_right,
                        color: Colors.black54,
                      ),
                    ],
                  ),
                ),
              );
            },
          ),
          CommonFormItem(
            "租金",
            hintText: "请输入租金",
            suffixText: "元/月",
            controller: TextEditingController(),
          ),
          CommonFormItem(
            "大小",
            hintText: "请输入房屋大小",
            suffixText: "m²",
            controller: TextEditingController(),
          ),
          CommonRadioFormItem(
            label: "租赁方式",
            options: ["合租", "整租"],
            value: _rentType,
            onChanged: (index) => setState(() => _rentType = index ?? 0),
          ),
          CommonSelectFormItem(
            label: "户型",
            options: ["一室", "二室", "三室", "四室"],
            value: _roomType,
            onChanged: (index) => setState(() => _roomType = index),
          ),
          CommonSelectFormItem(
            label: "楼层",
            options: ["低楼层", "中楼层", "高楼层"],
            value: _floorType,
            onChanged: (index) => setState(() => _floorType = index),
          ),
          CommonSelectFormItem(
            label: "朝向",
            options: ["东", "南", "西", "北"],
            value: _orientedType,
            onChanged: (index) => setState(() => _orientedType = index),
          ),
          CommonRadioFormItem(
            label: "装修",
            options: ["精装", "简装", "毛坯"],
            value: _decorationType,
            onChanged: (index) => setState(() => _decorationType = index ?? 0),
          ),
          CommonTitle("房屋照片"),
          CommonImagePicker(
            onChanged: (List<File> files) {},
          ),
          CommonTitle("房屋标题"),
          Container(
            padding: EdgeInsets.symmetric(horizontal: 10.0),
            child: TextField(
              controller: _info,
              decoration: InputDecoration(
                hintText: "请输入标题（例如：整租，小区名 xx栋 xx单元等）",
                hintStyle: TextStyle(fontSize: 14.0, color: Colors.grey[500]),
                border: InputBorder.none,
              ),
              textInputAction: TextInputAction.next,
            ),
          ),
          CommonTitle("房屋配置"),
          RoomApplicance(
            onChanged: (items) {},
          ),
          CommonTitle("房屋描述"),
          Container(
            padding: EdgeInsets.symmetric(horizontal: 10.0),
            margin: EdgeInsets.only(bottom: 100.0),
            child: TextField(
              controller: _desc,
              maxLines: 10,
              decoration: InputDecoration(
                hintText: "请输入房屋描述信息",
                hintStyle: TextStyle(fontSize: 14.0, color: Colors.grey[500]),
                border: InputBorder.none,
              ),
              textInputAction: TextInputAction.done,
            ),
          ),
        ],
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.miniCenterDocked,
      floatingActionButton: CommonFloatingActionButton(
        "提交",
        onTap: () {},
      ),
    );
  }
}
